export default {
	data(){
		return {
			// 当前页码
			page:1,
			// 是否正在加载
			isLoading: false,
			// 是否加载完毕
			noMore: false,
		}
	},
	methods: {
		// 加载
		async loadMore() {
			var vm = this;

			if(this.forbidLoad){
				this.forbidLoad = false;
			}
			else{
				if(!this.noMore){
					vm.toggle(true);
					this.nextPage(this.page);
					vm.isLoading = true;
					vm.initData(true);	
				}
			}
		},
		// 每次加载完毕调用 如果stop传了true  则直接取消
		loaded(list,stop){
			this.isLoading = false;
			
			if(stop){
				this.noMore = true
				return
			}

			if(list.rows.length >= list.total){
				this.noMore = true
			}else{
				this.noMore = false
			}
		},
		toggle(isMore, isLoading) {
			if (typeof isLoading === "undefined") {
				isLoading = isMore;
			}
			this.disabled = !!isMore;
			this.isLoading = !!isLoading;
		},
		nextPage(page = 1){
			this.page = page + 1;
			this.toggle(false, true);
		},
	}
}
